<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="/css/public.css?cache=<%=Math.random()%>">
    <link  href="../../hos_manage/images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="/css/palace/user/change_password.css?a=<%=Math.random()%>">
    <script src="/js/jquery-1.9.1.min.js"></script>
</head>
<body id="app" v-cloak>
<%@ include file="../../header.jsp"%>
<!--内容-->
<div class="containerone">
    <%@ include file="../../left_menu.jsp"%>
    <!--右边内容-->
    <div class="right_cont">
        <!--右边导航下面内容-->
        <div class="address-book">
            <div class="title">
                <div class="address-left show-block note">
                    <span>修改密码</span>
                </div>
            </div>
            <div class="password-container">
                <div class="each-password">
                    <div class="password-title">用户名:</div>
                    <div class="password-content">${user.name}</div>
                </div>
                <div class="each-password">
                    <div class="password-title">当前密码:</div>
                    <input class="password-input" type="password" v-model="form.oldpassword">
                </div>
                <div class="each-password">
                    <div class="password-title">新密码:</div>
                    <input class="password-input" type="password" v-model="form.password">
                </div>
                <div class="each-password">
                    <div class="password-title">确认密码:</div>
                    <input class="password-input" type="password" v-model="form.repassword">
                </div>
                <div class="password-submit" @click="submit()">确定</div>
            </div>
        </div>
    </div>
</div>
<dangertip v-if="dangerTipShow" :title="dangerTitle"></dangertip>
<meesagetip v-if="messageTipShow" :title="messageTitle"></meesagetip>
<delete v-if="deleteShow" :top="delete.top" :title="delete.title" :content="delete.content" :arg="delete.arg"></delete>
</body>
<%@ include file="/components/danger.jsp"%>
<%@ include file="/components/message.jsp"%>
<%@ include file="/components/delete.jsp"%>
<script src="http://cdn.bootcss.com/blueimp-md5/1.0.1/js/md5.min.js"></script>
<script src="/js/components/validate.js"></script>
<script>
    var HOSPITAL = "${user.hospital}";
    new Vue({
        el: "#app",
        data: {
            dangerTipShow: false,
            dangerTitle: "",
            messageTipShow: false,
            messageTitle: "",
            form: {
                oldpassword: "",
                password: "",
                repassword: "",
            },
            validateTag: {
                oldpassword: 0,
                password: 0,
                repassword: 0,
            },
            deleteShow: false,
            delete: {
                top: "",
                title: "",
                content: "",
                arg: {},
            }
        },
        methods: {
            submit: function() {
                var _this = this;
                for (var i in this.validateTag) {
                    var text = this.validateModule.done(this.form, i);
                    if (text != "") {
                        this.danger(text);
                        return;
                    }
                }
                if (this.form.oldpassword == this.form.password) {
                    this.danger("新密码与当前密码相同");
                    return;
                }
                if (this.form.password != this.form.repassword) {
                    this.danger("确认密码与新密码不相同");
                    return;
                }
                this.deleteShow = true;
                this.delete.top = "修改密码";
                this.delete.title = "确定修改密码吗?";
                this.delete.content = "修改密码后请重新登录";
                this.delete.arg = function() {
                    // 修改密码
                    $.ajax({
                        type: 'POST',
                        url: location.href,
                        data: {
                            act: "changePassword",
                            hospital: HOSPITAL,
                            user_name: "${user.userName}"   ,
                            old_password: md5(_this.form.oldpassword + ""),
                            new_password: md5(_this.form.password + ""),
                        },
                        success: function(res) {
                            res = JSON.parse(res);
                            if (res.errcode == 0) {
                                location.href="/quit.jsp";
                            } else {
                                _this.danger(res.errmsg);
                            }
                        },
                    });
                }
            },
            // 错误提示
            danger: function(title) {
                this.dangerTitle = title;
                this.dangerTipShow = true;
            },
        },
        components: {
            delete: deleteTip,
            dangertip: dangerTip,
            meesagetip: messageTip,
        },
        events: {
            // 错误提示
            dangerTipOver: function() {
                this.dangerTipShow = false;
            },
            deleteCancel: function() {
                this.deleteShow = false;
            },
        },
        ready: function () {
            var validateModule = validateJS();
            validateModule.addValidate("oldpassword", "password", "当前密码");
            validateModule.addValidate("password", "password", "新密码");
            validateModule.addValidate("repassword", "password", "确认密码");
            this.validateModule = validateModule;
        }
    });
</script>
</html>
